package com.course.design.controller;

import cn.hutool.json.JSONObject;
import com.course.design.common.Result;
import com.course.design.entity.Dept;
import com.course.design.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 描述:
 *
 * @author qinlianji
 * @create 2020-03-15
 */
@Api(tags = {"部门管理"})
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @ApiOperation(value = "查询有哪些部门")
    @GetMapping("/queryList")
    public Result queryList() {
        return Result.success(deptService.queryList());
    }

    @ApiOperation(value = "分页查询所有部门信息")
    @GetMapping("/queryPage")
    public Result queryPage(int start, int limit, String deptname){
        return Result.success(deptService.queryPage(start, limit, deptname));
    }

    @ApiOperation(value = "保存或新增")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Dept dept) {
        deptService.saveOrUpdate(dept);
        return Result.success(dept);
    }

    @ApiOperation(value = "删除员工")
    @GetMapping("/delete/{deptbsId}")
    public Result delete(@PathVariable(name = "deptbsId") String deptbsId) {
        deptService.deleteById(deptbsId);
        return Result.success();
    }

    @ApiOperation(value = "批量删除员工")
    @PostMapping("/batchDelete")
    public Result batchDelete(@RequestBody JSONObject json) {
        deptService.batchDeleteById((String)json.get("ids"));
        return Result.success();
    }
}
